package com.example.restaurantclient.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;

import com.example.restaurantclient.Adapter.CustomNewsAdapter;
import com.example.restaurantclient.Adapter.CustomRestaurantAdapter;
import com.example.restaurantclient.Entities.News;
import com.example.restaurantclient.Entities.Restaurant;
import com.example.restaurantclient.R;
import com.example.restaurantclient.WheelDialog.HeightWheelDialog;

import java.util.ArrayList;
import java.util.List;

public class QueueUpListActivity extends AppCompatActivity {
    private ListView listView;
    private List<Restaurant> restaurantsItems=new ArrayList<>();
    private SearchView searchView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_queue_up_list);

        listView = findViewById(R.id.house_list);
        searchView = findViewById(R.id.cookie_manage_searchView);
        //新建数据
        initData();
        final CustomRestaurantAdapter customNewsAdapter = new CustomRestaurantAdapter(QueueUpListActivity.this, restaurantsItems, R.layout.restaurant_list_item);
        listView.setAdapter(customNewsAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });
        // 设置搜索文本监听
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    switch (query)
                    {
                        case "国泰":
                            restaurantsItems.clear();
                            Restaurant restaurant1=new Restaurant("国泰宏城店",11.3f,"北京市顺义区国泰宏城大卖场F1",4,7,3,"0312-103789",40.12962886207276f,116.63480658743666f,81);
                            restaurantsItems.add(restaurant1);
                            customNewsAdapter.notifyDataSetChanged();
                            listView.setAdapter(customNewsAdapter);
                            break;
                        case "新世界":
                            restaurantsItems.clear();
                            Restaurant restaurant2=new Restaurant("新世界店",3.5f,"北京市顺义区新顺南大街新世界百货F1",2,4,1,"0312-156789",40.12689305931414f,116.65163476679609f,21);
                            restaurantsItems.add(restaurant2);
                            customNewsAdapter.notifyDataSetChanged();
                            listView.setAdapter(customNewsAdapter);
                            break;
                        case "顺康":
                            restaurantsItems.clear();
                            Restaurant restaurant3=new Restaurant("顺康路店",8.6f,"北京市顺义区顺康路中晟景苑",5,1,4,"0312-102269",40.11238777407324f,116.6749243876724f,32);
                            restaurantsItems.add(restaurant3);
                            customNewsAdapter.notifyDataSetChanged();
                            listView.setAdapter(customNewsAdapter);
                            break;
                    }
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    return false;
                }
            });
        }


    }

    //初始化数据
    public void initData(){
        Restaurant restaurant1=new Restaurant("国泰宏城店",11.3f,"北京市顺义区国泰宏城大卖场F1",4,7,3,"0312-103789",40.12962886207276f,116.63480658743666f,82);
        Restaurant restaurant2=new Restaurant("新世界店",3.5f,"北京市顺义区新顺南大街新世界百货F1",2,4,1,"0312-156789",40.12689305931414f,116.65163476679609f,31);
        Restaurant restaurant3=new Restaurant("顺康路店",8.6f,"北京市顺义区顺康路中晟景苑",5,1,4,"0312-102269",40.11238777407324f,116.6749243876724f,42);
        restaurantsItems.add(restaurant1);
        restaurantsItems.add(restaurant2);
        restaurantsItems.add(restaurant3);
    }
}
